Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

aio: add h1 title to floating table of contents #16959

Merged
merged 8 commits into from
May 24, 2017

Conversation

petebacondarwin
Copy link
Member

Closes #16900

@petebacondarwin petebacondarwin added comp: aio action: review The PR is still awaiting reviews from at least one requested reviewer labels May 23, 2017
@petebacondarwin petebacondarwin added this to REVIEW in docs-infra May 23, 2017

Observable.combineLatest(this.tocService.activeItemIndex, this.items.changes.startWith(this.items))
// We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes,
// which are, in turn, triggered rendering that happened due to a ChangeDetection.
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

English !!

@petebacondarwin
Copy link
Member Author

I rebased, fixed the conflict, and broke up the big commit into smaller ones to make the refactoring more easy to follow.

@mary-poppins
Copy link

The angular.io preview for a4fecef is available here.

@mary-poppins
Copy link

The angular.io preview for c496a15 is available here.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A few nit-picks. Nothing blocking.
Loved the refactorings ❤️

// We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes,
// which, in turn, are caused by the rendering that happened due to a ChangeDetection.
// Without asap, we would be updating the model while still in a ChangeDetection handler, which is disallowed by Angular.
Observable.combineLatest(this.tocService.activeItemIndex.subscribeOn(asap), this.items.changes.startWith(this.items))
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💯

import 'rxjs/add/operator/takeUntil';

import { ScrollService } from 'app/shared/scroll.service';
import { TocItem, TocService } from 'app/shared/toc.service';

type TocType = 'None' |'Floating' |'EmbeddedSimple' |'EmbeddedExpandable';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No whitespace after |? 😞

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

<div *ngIf="hasToc" [class.collapsed]="isCollapsed">
<button *ngIf="!isEmbedded" type="button" class="toc-heading"
(click)="toTop()" title="Top of page">Contents</button>
<div *ngIf="type != 'None'" class="toc-inner" [class.collapsed]="isCollapsed">
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OOC, why != vs !==?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

typo

'EmbeddedExpandable' :
'EmbeddedSimple' :
'Floating' :
'None';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ternary operator hell 😁

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah! It's a pyramid of beauty!

Copy link
Member

@gkalpak gkalpak May 24, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just to be clear: I like it 😃

@@ -67,7 +56,8 @@ aio-toc > div {
}

button.toc-heading,
div.toc-heading {
div.toc-heading,
ul.toc-list li.h1 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we need the element specifiers at all. Why not just .toc-heading, .toc-list .h1 { ... }?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That is probably correct. I was just sort of following the convention there already.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But I think that Stef will change some of this anyway

@@ -134,7 +124,7 @@ aio-toc > div {
transition: all 0.3 ease-in-out;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not directly related to this PR, but I noticed this value is invalid and causes the style to be ignored. It should be 0.3s (the s is currently missing).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll sneak that in.

display: block;
height: 1px;
width: 40%;
margin: 24px 0px 10px;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

24px feels too much. margin: 10px 0 looks better imo 😃

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is due to change in Stef's PR.

tocList[i].isSecondary = true;
}
}
const count = this.tocList.reduce((c, item) => item.level !== 'h1' ? c + 1 : c, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: this.tocList.filter(item => item.level !== 'h1').length is slightly more readable 😳

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but slower and uses more memory :-P

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know, I know 😞 But Igor said to opt for readability over performance 😛

<a [href]="toc.href" [innerHTML]="toc.content"></a>
</li>
<ng-container *ngFor="let toc of tocList; let i = index">
<li #tocItem title="{{toc.title}}" *ngIf="type == 'Floating' || toc.level != 'h1'"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It might make sense to avoid this ngIf, by separating the h1 element from the rest (in the component).

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought about that but it just moves the complexity somewhere else.
Not displaying the h1 IMO is a visual choice, hence the responsibility of the template.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The decision about dislaying it or not will still be in the template. But the template won't have to "extract" it from the tocList (which sounds rather "business-logic-y").
I don't feel at all strognly about it, though.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think that then you would need complexity in both the component class (to extract the h1) and then in the template (where it would need to duplicate the li element for the h1).

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

¯\_(ツ)_/¯

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually also it become even more complex when you then try to get the activeIndex to line up. This way, it just works :-)

fixture.detectChanges();
expect(tocComponentDe.queryAllNodes(By.css('li')).length).toBe(3);
});

it('should only display H2 and H3 TocItems', () => {
tocService.tocList.next([tocItem('Heading A', 'h1'), tocItem('Heading B'), tocItem('Heading C')]);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No test for H3 😟

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😱

@petebacondarwin
Copy link
Member Author

@gkalpak Pushed a bunch of fixes from your feedback, some of which will be squashed. PTAL

@mary-poppins
Copy link

The angular.io preview for 4bb3bc7 is available here.

Copy link
Member

@gkalpak gkalpak left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Still LGTM


<button *ngIf="hasSecondary" type="button" class="toc-heading embedded secondary"
(click)="toggle(false)"
<button *ngIf="type == 'EmbeddedExpandable'" type="button" (click)="toggle(false)"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's one more here 😛

import 'rxjs/add/operator/takeUntil';

import { ScrollService } from 'app/shared/scroll.service';
import { TocItem, TocService } from 'app/shared/toc.service';

type TocType = 'None' |'Floating' |'EmbeddedSimple' | 'EmbeddedExpandable';
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are more missing whitespaces here.

@@ -92,3 +92,7 @@ export class TocComponent implements OnInit, AfterViewInit, OnDestroy {
this.scrollService.scrollToTop();
}
}

function count<T>(array: T[], fn: (T) => boolean) {
return array.reduce((count, item) => fn(item) ? count + 1 : count, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return array.filter(fn).length is more readable 😛

This makes the styling less fragile to changes in the HTML
We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes,
which, in turn, are caused by the rendering that happened due to a ChangeDetection.

Without asap, we would be updating the model while still in a ChangeDetection handler,
which is disallowed by Angular.
@mary-poppins
Copy link

The angular.io preview for c9f93b9 is available here.

@petebacondarwin petebacondarwin added action: merge The PR is ready for merge by the caretaker and removed action: review The PR is still awaiting reviews from at least one requested reviewer labels May 24, 2017
@petebacondarwin petebacondarwin moved this from REVIEW to MERGE in docs-infra May 24, 2017
@chuckjaz chuckjaz merged commit 966eb2f into angular:master May 24, 2017
@petebacondarwin petebacondarwin removed this from MERGE in docs-infra May 25, 2017
@petebacondarwin petebacondarwin deleted the aio-toc-floating-title branch May 25, 2017 10:05
gkalpak added a commit to gkalpak/angular that referenced this pull request May 30, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
gkalpak added a commit to gkalpak/angular that referenced this pull request May 30, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
gkalpak added a commit to gkalpak/angular that referenced this pull request May 30, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
gkalpak added a commit to gkalpak/angular that referenced this pull request May 30, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
vicb pushed a commit that referenced this pull request May 30, 2017
There seems to have been a bad rebase of #16228 on top of #16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes #17098
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
* refactor(aio): use explicit CSS class for TOC container

This makes the styling less fragile to changes in the HTML

* fix(aio): schedule TocComponent.activeIndex updates via AsapScheduler

We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes,
which, in turn, are caused by the rendering that happened due to a ChangeDetection.

Without asap, we would be updating the model while still in a ChangeDetection handler,
which is disallowed by Angular.

* refactor(aio): do not instantiate floating ToC if not displayed

* feat(aio): display the h1 at the top of the floating TOC

Closes angular#16900

* refactor(aio): combine the TOC booleans flags into a "type" state

* refactor(aio): remove unnecessary `hostElement` property

* fix(aio): ensure that transition works on TOC

* fix(aio): use strict equality in ToC template
asnowwolf pushed a commit to asnowwolf/angular that referenced this pull request Aug 11, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
* refactor(aio): use explicit CSS class for TOC container

This makes the styling less fragile to changes in the HTML

* fix(aio): schedule TocComponent.activeIndex updates via AsapScheduler

We use the `asap` scheduler because updates to `activeItemIndex` are triggered by DOM changes,
which, in turn, are caused by the rendering that happened due to a ChangeDetection.

Without asap, we would be updating the model while still in a ChangeDetection handler,
which is disallowed by Angular.

* refactor(aio): do not instantiate floating ToC if not displayed

* feat(aio): display the h1 at the top of the floating TOC

Closes angular#16900

* refactor(aio): combine the TOC booleans flags into a "type" state

* refactor(aio): remove unnecessary `hostElement` property

* fix(aio): ensure that transition works on TOC

* fix(aio): use strict equality in ToC template
juleskremer pushed a commit to juleskremer/angular that referenced this pull request Aug 28, 2017
There seems to have been a bad rebase of angular#16228 on top of angular#16959, which affected
ToC styles from both PRs. This commit restores the horizontal line under `.h1`
elements and the vertical blue bar on the left-hand side of the ToC (with the
circle running along the bar to indicate the active section).

Fixes angular#17098
@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 11, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
action: merge The PR is ready for merge by the caretaker cla: yes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

aio: replace "contents" with h1 text in floating right TOC
5 participants